﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Administrator
{
    public partial class fNewChannel : Form
    {
        public Int32 ChannelID = 0;
        private Boolean LoadSetting = false;        
        private Int32[] tmpDisableChannelID = new Int32[0];

        public fNewChannel()
        {
            InitializeComponent();
        }

        public void FillFields(Int32 NewChannelID, Int32[] DisableChannelID, Int32 MaxChannelNumber)
        {
            LoadSetting = true;

            ChannelID = NewChannelID;
            if (DisableChannelID != null)
            {
                tmpDisableChannelID = new Int32[DisableChannelID.Length];
                for (Int32 i = 0; i < tmpDisableChannelID.Length; i++)
                    tmpDisableChannelID[i] = DisableChannelID[i];
            }
            if (MaxChannelNumber >= 0)
            {
                nudChannel.Maximum = MaxChannelNumber + 1;
                nudChannel.Value = ChannelID + 1;
            }
            else nudChannel.Enabled = false; 

            LoadSetting = false;
        }

        private void nudChannel_ValueChanged(object sender, EventArgs e)
        {
            if (!LoadSetting) ChannelID = (Int32)(nudChannel.Value - 1);
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            Boolean Result = true;
            for (Int32 i = 0; i < tmpDisableChannelID.Length; i++)
            {
                if (tmpDisableChannelID[i] == ChannelID)
                {
                    Result = false;
                    break;
                }
            }
            if (Result)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
            else MessageBox.Show(cConst.JOIN_CHANNEL_NUM_ERROR_CAP, cConst.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
        private void fNewChannel_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13) btnOk_Click(btnOk, null);
            if (e.KeyChar == 27) btnClose_Click(btnClose, null);
        }        
    }
}
